// 引入
import JSEncrypt from 'jsencrypt';

/*
 * 加密
 * @param publicKey 公钥
 * @param data 要加密的数据
 */
export function encryptedData(publicKey, data) {
  // 新建JSEncrypt对象
  const encryptor = new JSEncrypt(); // 设置公钥
  encryptor.setPublicKey(publicKey); // 加密数据
  return encryptor.encrypt(data);
}

// 私钥
const privateKey = `xxxx`;

// 解密
export function decrypt(msg) {
  let decrypt = new JSEncrypt();
  decrypt.setPrivateKey(privateKey);
  var decryptMsg = decrypt.decrypt(msg);
  return decryptMsg;
}
